package com.lanyou.cook.repository;

import java.util.Date;
import java.util.List;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.Repository;
import org.springframework.data.rest.core.annotation.RestResource;

import com.lanyou.cook.entity.domain.InterfaceExecutionResult;

public interface InterfaceExecutionResultRepository extends Repository<InterfaceExecutionResult, String>, JpaSpecificationExecutor<InterfaceExecutionResult> {

	@RestResource(exported = false)
	long countByScheduleIdAndRunResult(String scheduleId, String runResult);
	
	@RestResource(exported = false)
	List<InterfaceExecutionResult> findByRunResultAndRunBeginTimeBefore(String runResult, Date date);
	
	long count();
	
	boolean exists(String id);
	
	@RestResource(exported = false)
	<S extends InterfaceExecutionResult> S save(S entity);	// could expose REST API
	
	<S extends InterfaceExecutionResult> List<S> save(Iterable<S> entities);
	
	@RestResource(exported = true)
	@RequiresPermissions(value={"historyInterfaceImplementationQuery","interfaceSchedulingHistoryQuery:view","failuredWarningInfoReport:view","implementationInterfaceQuery:view"}, logical=Logical.OR)
	InterfaceExecutionResult findOne(String id);	// could expose REST API
	
	InterfaceExecutionResult getOne(String id);
	
	// 以下三个接口只能选一个暴露为REST API
	
	@RestResource(exported = false)
	List<InterfaceExecutionResult> findAll();	// could expose REST API
	
	@RestResource(exported = false)
	List<InterfaceExecutionResult> findAll(Sort sort);	// could expose REST API
	
	@RestResource(exported = true)
	@RequiresPermissions(value={"historyInterfaceImplementationQuery","interfaceSchedulingHistoryQuery:view","failuredWarningInfoReport:view","implementationInterfaceQuery:view"}, logical=Logical.OR)
	Page<InterfaceExecutionResult> findAll(Pageable pageable);	// could expose REST API
	
	List<InterfaceExecutionResult> findAll(Iterable<String> ids);
	
	void flush();
	
	<S extends InterfaceExecutionResult> S saveAndFlush(S entity);
	
	void deleteInBatch(Iterable<InterfaceExecutionResult> entities);
	
	void deleteAllInBatch();

	void delete(String interfaceExecutionResultId);
}

